package com.crm.system.controller.reminditem;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.qo.reminditem.RemindItemQO;
import com.crm.model.vo.reminditem.RelatedRemindVO;
import com.crm.system.service.reminditem.SysRemindItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * @Description: 提醒事项
 * @Author lixq-f
 * @Date 2021/4/21
 * @Version V1.0
 **/
@RestController
@RequestMapping("/remindItem")
@Slf4j
public class SysRemindItemController {


    @Autowired
    private SysRemindItemService itemService;


    @PostMapping("/addItem")
    public DataResponse addItem(@Validated @RequestBody RemindItemQO itemQO, HttpServletResponse response) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), itemService.insert(itemQO));
    }


    @PostMapping("/updateItem")
    public DataResponse updateItem(@Validated @RequestBody RemindItemQO itemQO) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), itemService.update(itemQO));
    }


    @GetMapping("/deleteItemById/{id}")
    public DataResponse deleteItemById(@PathVariable(value = "id") String id) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), itemService.deleteById(id));
    }


    @GetMapping("/selectItemById/{id}")
    public DataResponse selectRemindItemById(@PathVariable("id") String id) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), itemService.selectRemindItemById(id));
    }


    @GetMapping("/selectList")
    public DataResponse selectListByCreatePeopleId() {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), itemService.selectListByCreatePeopleId());
    }


    @GetMapping("/selectRemindItems")
    public DataResponse selectRemindItem() {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), itemService.getRemindItem());
    }

    /***
     * @Description:获取相关提醒列表
     * @param selectDate 查询日期
     * @param pageIndex/pageSize 页号/每页显示个数
     * @Author: luojie
     * @Date: 2021/4/27 8:41
     */
    @GetMapping("/selectRelatedRemindList")
    public DataResponse selectRelatedRemindList(@RequestParam String selectDate,
                                                @RequestParam(value = "pageIndex", required = true) Integer pageIndex,
                                                @RequestParam(value = "pageSize", required = true) Integer pageSize,
                                                @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                                @RequestParam(value="sortOrder",required = false) String sortOrder//排序规则(asc/desc)
                                                ) throws ParseException {
        DhPageInfo<RelatedRemindVO> relatedRemindVOS = itemService.selectRelatedRemindList(selectDate,pageIndex,pageSize,sortName,sortOrder);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), relatedRemindVOS);
    }


}
